package org.ahuanlien.crm.web.controller;

import org.ahuanlien.crm.domain.TemOrder;
import org.ahuanlien.crm.query.TemOrderQueryObject;
import org.ahuanlien.crm.query.QueryObject;
import org.ahuanlien.crm.service.ITemOrderService;
import org.ahuanlien.crm.util.JSONResult;
import org.ahuanlien.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("temOrder")
public class TemOrderController {

	@Autowired
	private ITemOrderService temOrderService;

	@RequestMapping("selectAll")
	@ResponseBody
	public List<TemOrder> selectAll(QueryObject qo) {
		return temOrderService.selectAll();
	}

	//打开页面和数据获取分开
	@RequestMapping("view")
	public String view() {

		return "temOrder/view";
	}

	@RequestMapping("query")
	@ResponseBody
	public PageResult query(TemOrderQueryObject qo) {
		PageResult result = temOrderService.query(qo);
		return result;
	}

	@RequestMapping("saveOrUpdate")
	@ResponseBody
	public JSONResult saveOrUpdate(TemOrder temOrder, Integer duration) {
		try {
			if (temOrder.getId() != null) {
				temOrderService.updateByPrimaryKey(temOrder);
			} else {
				temOrderService.insert(temOrder);
			}
			return new JSONResult();
		} catch (Exception e) {
			e.printStackTrace();
			return new JSONResult().mark("保存失败");
		}
	}

	@RequestMapping("delete")
	@ResponseBody
	public JSONResult delete(Long id) {
		try {
			temOrderService.deleteByPrimaryKey(id);
		} catch (Exception e) {
			e.printStackTrace();
			return JSONResult.mark("操作失败");
		}
		return JSONResult.success("操作成功");
	}

	@RequestMapping("audit")
	@ResponseBody
	public JSONResult audit(Long id) {
		try {
			temOrderService.audit(id);
		} catch (Exception e) {
			e.printStackTrace();
			return JSONResult.mark("操作失败");
		}
		return JSONResult.success("操作成功");
	}


}
